package com.axjy.qg.controller;

import com.axjy.qg.service.QgServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class QgController {

    @Resource
    private QgServiceImpl qgService;

    @Value("${server.port}")
    private String port;

    @RequestMapping("/qg/show")
    public String show(){
        return "现在使用的tomcat端口号为server.port="+port;
    }

    @RequestMapping("/qg/buy")
    public Map buy(String id){
        Map map=new HashMap();
        try{
            qgService.changeCount(id);
            map.put("success",true);
            map.put("msg","抢购成功！");
        }catch (RuntimeException ex){
            map.put("success",false);
            map.put("msg",ex.getMessage());
        }
        return map;
    }


}
